import  random
import smtplib
from email.mime.text import MIMEText
from email.header import Header
from email.utils import formataddr
from email.mime.multipart import MIMEMultipart

sender_email = 'walrus1983@126.com'  # 发送方邮箱
sender_password = 'YXUNi39iqZiDWqxb'

# 你要把邮件发给谁
receiver_email = "walrus1983@qq.com"

text_content = '这是一封测试邮件'
content = '''
<h1 style="color:red;>您的验证码是：{}</h1>
'''.format(random.randint(10000,99999)) + text_content

# 正文
# content = "测试邮件内容"
msg = MIMEMultipart()
msg.attach(MIMEText(content,'html','utf-8'))

msg["From"] = formataddr(["walrus1983@126.com",sender_email])
msg["To"] = formataddr(["walrus1983@qq.com",receiver_email])
msg["Subject"] = Header("慕慕手记验证码","utf-8")


s = smtplib.SMTP_SSL("smtp.126.com",465)  # 邮箱服务器及端口号
# s.starttls()
s.login(sender_email,sender_password)
s.sendmail(sender_email,receiver_email,msg.as_string())


